import frappe

def show_processlist():
    """显示数据库进程列表，支持达梦数据库"""
    frappe.only_for("System Manager")

    return frappe.db.multisql(
        {
            "postgres": """
            SELECT pid AS "Id",
                query_start AS "Time",
                state AS "State",
                query AS "Info",
                wait_event AS "Progress"
            FROM pg_stat_activity""",
            "mariadb": "show full processlist",
            "dm": """
            SELECT 
                SESSIONID AS "Id",
                START_TIME AS "Time",
                STATUS AS "State",
                SQL_TEXT AS "Info",
                CASE 
                    WHEN WAIT_EVENT IS NOT NULL THEN WAIT_EVENT
                    ELSE WAIT_CLASS 
                END AS "Progress"
            FROM V$SESSION 
            WHERE USERNAME = USER
            ORDER BY START_TIME DESC""",
        },
        as_dict=True,
    )
